/**
  ******************************************************************************
  * @file    COMM_DRIVER.h
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   Outputs Driver
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 



/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef  __COMM_DRIVER_H__
#define  __COMM_DRIVER_H__


#ifdef __cplusplus
 extern "C" {
#endif


/**
  * @brief  INCLUDE FILES.
  */


/**
  * @brief GLOBALS RAM definition
  */
#ifdef   COMM_DRIVER_GLOBALS
#define  COMM_DRIVER_EXT
#else
#define  COMM_DRIVER_EXT  extern
#endif


#define TIM4CountCLK_FREQ               ((uint32_t) 1000000)   /* HZ */
                                                    

/* Communication Timer */
#define CfgTIM4_RCCPeriph               RCC_APB1Periph_TIM4
#define CfgTIM4_Prescaler               (uint16_t)(SYSTIM2T7CLK_FREQ/TIM4CountCLK_FREQ-1)
#define CfgTIM4_CounterMode             TIM_CounterMode_Up
#define CfgTIM4_Period                  65535
#define CfgTIM4_ClockDivision           TIM_CKD_DIV1
#define CfgTIM4_RepetitionCounter       0
#define CfgTIM4                         TIM4
#define CfgTIM4_ITx                     TIM_IT_Update
#define CfgTIM4_FLAGx                   TIM_FLAG_Update
#define CfgTIM4_IRQChannel              TIM4_IRQn
#define CfgTIM4_IRQPrePrio              0x0D
#define CfgTIM4_IRQSubPrio              0x0E

/* RS232 */
#define RS232TIM_IT_CCx                    TIM_IT_CC1
#define RS232TIM_FLAG_CCx                  TIM_FLAG_CC1
#define RS232TIM_OCMode                    TIM_OCMode_Timing     
#define RS232TIM_OutputState               TIM_OutputState_Enable
#define RS232TIM_OutputNState              TIM_OutputNState_Disable
#define RS232TIM_Pulse                     18000                           //18ms
#define RS232TIM_OCPolarity                TIM_OCPolarity_Low 
#define RS232TIM_OCNPolarity               TIM_OCNPolarity_Low 
#define RS232TIM_OCIdleState               TIM_OCIdleState_Reset 
#define RS232TIM_OCNIdleState              TIM_OCNIdleState_Reset 
                                        
/* WIFI */                             
#define WIFITIM_IT_CCx                    TIM_IT_CC3
#define WIFITIM_FLAG_CCx                  TIM_FLAG_CC3
#define WIFITIM_OCMode                    TIM_OCMode_Timing     
#define WIFITIM_OutputState               TIM_OutputState_Enable
#define WIFITIM_OutputNState              TIM_OutputNState_Disable
#define WIFITIM_Pulse                     51000                           //51ms
#define WIFITIM_OCPolarity                TIM_OCPolarity_Low 
#define WIFITIM_OCNPolarity               TIM_OCNPolarity_Low 
#define WIFITIM_OCIdleState               TIM_OCIdleState_Reset 
#define WIFITIM_OCNIdleState              TIM_OCNIdleState_Reset 

/* USB */
#define USBTIM_IT_CCx                      TIM_IT_CC2
#define USBTIM_FLAG_CCx                    TIM_FLAG_CC2
#define USBTIM_OCMode                      TIM_OCMode_Timing     
#define USBTIM_OutputState                 TIM_OutputState_Enable
#define USBTIM_OutputNState                TIM_OutputNState_Disable
#define USBTIM_Pulse                       30000                           //30ms
#define USBTIM_OCPolarity                  TIM_OCPolarity_Low 
#define USBTIM_OCNPolarity                 TIM_OCNPolarity_Low 
#define USBTIM_OCIdleState                 TIM_OCIdleState_Reset 
#define USBTIM_OCNIdleState                TIM_OCNIdleState_Reset 


/* USB_DETECTION */
#define RCCPeriph_USBDetection             RCC_APB2Periph_GPIOC
#define GPIOModeI_USBDetection             GPIO_Mode_IPD
#define GPIOSpeed_USBDetection             GPIO_Speed_2MHz
#define GPIOxPort_USBDetection             GPIOC
#define GPIOxBitx_USBDetection             GPIO_Pin_10



COMM_DRIVER_EXT void PORInit_CommTimer  (void);
COMM_DRIVER_EXT void TIM4_IRQHandler(void);

#ifdef __cplusplus
}
#endif


#endif   /*  __COMM_DRIVER_H__  */

/******************* (C) COPYRIGHT 2010 Feirui *****END OF FILE****/